package com.junko.core.tool;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;

public class ToolFile {
    private static final Logger logger = LogManager.getLogger(ToolFile.class);

    public static void delete(File file) {
        if (file != null && file.exists()) {
            if (file.isFile()) {
                if(!file.delete()){
                    logger.error("文件删除失败:"+file.getAbsolutePath());
                }
            }
            else if (file.isDirectory()) {
                File files[] = file.listFiles();
                for (int i=0; i<files.length; i++) {
                    delete(files[i]);
                }
            }
            file.delete();
        }
    }
    public static String getExtention(String fileName){
        return fileName.substring(fileName.lastIndexOf("."),fileName.length());
    }
}
